package xyz.xiangyushui.util.htmltoString;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class EliminateBlank {
	private File input;
	private File out;
	
	
	
	public EliminateBlank(String input, String out) {
		super();
		this.input = new File(input);
		this.out = new File(out);
	}

	public void start(){
		String content=read();
		System.out.println(content);
		write(content.replaceAll("\r\n", " ").replaceAll("\"", "'"));
	}
	
	private void write(String data){
        BufferedWriter bufferWritter = null;
		try {
			bufferWritter = new BufferedWriter(new FileWriter(out));
			bufferWritter.write(data);
		} catch (IOException e1) {
			e1.printStackTrace();
		}finally{
			try {
				bufferWritter.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	private String read(){
		Scanner s=null;
		String result="";
		try {
			s=new Scanner(new FileInputStream(input));
			s.useDelimiter("^");
			result=s.hasNext()?s.next():"";
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}finally{
			if(s!=null){
				s.close();
			}
		}
		return result;
	}
	
	public static void main(String[] args){
		String dir=System.getProperty("user.dir")+"/src/xyz/xiangyushui//util/htmltoString";
		EliminateBlank e=new EliminateBlank(dir+"/input", dir+"/output");
		e.start();
	}

}
